package leetcode_301_400;

public class LeeCode_390 {
    public static void main(String[] args) {

    }
    private static int lastRemaining(int n) {
        int cnt = n, step = 1, st = 1, k = 0;
        while (cnt > 1){
            if (k % 2 == 0){
                st = st + step;
            }else {
                st = (cnt % 2) == 0 ? st : st + step;
            }
            k++;
            cnt >>>= 1;
            step <<= 1;
        }
        return st;
    }
}
